/*
 @author chenshiyu
 @date 2017.08.10
 @description https://fangxin.com相关的管理模块，包含mutations 和 actions
 */

import Vue from 'vue'
import api from '../../util/api.js'
import * as types from './fxx-types.js'

let state = {
    categorySearchList: [], // 三级品类列表 用于关联品类、关联文章等
}

const mutations = {
    [types.MU_CATEGORYS](state, data){
        state.categorySearchList = data
    }
}

const actions = {
    [types.ACTION_CATEGORYS]({commit}, param){
        (async () => {
            if (state.categorySearchList.length) {
                return;
            }
            let res = await Vue.$_http(api.cateSearchList, 'post', {
                param: JSON.stringify({})
            })
            commit(types.MU_CATEGORYS, res.category_list)
        })()
    }
}

const getters = {
    cateogrySelectData(state){
        let res = [];
        for (let {category_id, category_name} of state.categorySearchList) {
            res.push({
                label: category_name,
                key: category_id,
                disabled: false,
            })
        }
        return res;
    }
}

export default {
    state,
    mutations,
    actions,
    getters
}



